package com.my.demo.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.my.demo.dao.BookDao;
import com.my.demo.model.Book;
import com.my.framework.dao.BaseService;
import com.my.framework.dao.Pagination;


@Service
public class BookService extends BaseService {

	@Autowired
	private BookDao bookDao;

	//新增,设置主键和创建时间
	public Book insert(Book book) {
		book.setBookId(newId());
		book.setCreateTime(new Date());
		bookDao.insert(book);
		return book;
	}

	//通过主键批量删除
	public int deleteById(Long[] bookId) {
		if(bookId.length==0) {
			return 0;
		}
		return bookDao.deleteById(bookId);
	}

	//通过主键更新
	public Book updateById(Book book) {
		bookDao.updateById(book);
		return book;
	}

	//普通查询
	public List<Book> select(Book book) {
		return bookDao.select(book);
	}
	
	//通过主键获得
	public Book get(Long bookId) {
		return bookDao.get(bookId);
	}

	//分页查询
	public Pagination selectPage(Book book, Integer offset, Integer limit) {
		return super.selectPage(book, bookDao,offset, limit);
	}
	
	public int updateByBookName(Book book) {
		return bookDao.updateByBookName(book);
	}
}
